home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - Mac PPC / doc / mindy.txt < prev    next >
Encoding:
Text File  |  1995-03-15  |  62.1 KB  |  1,754 lines  |  [TEXT/MMCC]

  1. [NOTE: This file has been generated by a series of translation tools that
  2.  converted an original FrameMaker .mif file to this .txt file.  The
  3.  conversion tools created the table of contents and uppercased all
  4.  identifiers.  The printed representation of all identifiers in this
  5.  interface is lowercase.  The conversion tools also sometimes drops hyphens
  6.  from identifiers, so if you think a name should have a hyphen in it, it
  7.  probably does.  It is not worth the effort to manually fix this .txt file
  8.  to correct these problems.]
  9.  
  10.  
  11.                       THE MINDY COMPILER AND INTERPRETER
  12.                       ==================================
  13.  
  14. ------------------------------------------------------------------------------
  15.  
  16. Table of Contents
  17. -----------------
  18.  
  19. 1.  Introduction
  20.  
  21. 2.  Hello, World
  22.  
  23. 3.   The Main Routine
  24.  
  25. 4.   Multiple Files
  26.  
  27. 5.  Syntax Errors
  28.  
  29. 6.  Runtime Errors
  30.  
  31. 7.  Internal Lossage
  32.  
  33. 8.  Dylan vs. Mindy Language Issues
  34.  
  35. 9.  Built-in Libraries and Modules
  36.  
  37. 10.  Using Libraries and Modules
  38.  
  39. 11.  The Extensions Module
  40.  
  41.     11.1.  Generally Useful Definitions
  42.  
  43.     11.2.  Debugger Customizations
  44.  
  45.     11.3.  Tables
  46.  
  47.     11.4.  Exiting Applications
  48.  
  49.     11.5.  Weak Pointers
  50.  
  51.     11.6.  Collections
  52.  
  53. 12.   The System Module
  54.  
  55. 13.  The Introspection Module
  56.  
  57.     13.1.  Functions
  58.  
  59.     13.2.  Classes and Instances
  60.  
  61.     13.3.  Types
  62.  
  63.     13.4.  Miscellaneous
  64.  
  65. 14.  The File-descriptor Module
  66.  
  67. 15.  The Cheap-io Module
  68.  
  69. 16.  The Threads Module
  70.  
  71.     16.1.  Classes and Functions
  72.  
  73.     16.2.  Examples
  74.  
  75. 17.   Streams Library
  76.  
  77. 18.  Integers
  78.  
  79. 19.  Miscellaneous Implementation Choices
  80.  
  81. 20.  Copyright and Terms of Use
  82.  
  83. ------------------------------------------------------------------------------
  84.  
  85.     Copyright (c) 1994  Carnegie Mellon University All rights reserved.
  86.     Refer to the end of this document for precise terms of use.
  87.  
  88. The Gwydion Project would like to thank those on the net that have
  89. contributed code patches and bug reports for Mindy:
  90.  
  91.     Adam Alpern, Patrick Beard, Steve Strassman, Scott Collins, Ed Gamble,
  92.     Bruno Haible, John Shen, Galen Hunt, Richard Lynch, Dan Ratner, Court
  93.     Demas, Miles Bader, Kelly Murray, Nick Thompson, Brent Benson, Brian
  94.     Rogoff
  95.  
  96. Special thanks for a major effort to Roger Critchlow for enhancements to
  97. Mindy.
  98.  
  99. 1.  Introduction
  100. ----------------
  101. Mindy is an implementation of a language that is very much like the language
  102. described in the DylanTM INTERIM REFERENCE MANUAL (DIRM).  THE NAME MINDY IS
  103. DERIVED FROM "MINDY IS NOT DYLAN YET", AND AS THE NAME IMPLIES,
  104. MINDY IS INCOMPLETE.  MINDY IS INCOMPLETE FOR THE FOLLOWING REASONS:
  105.  
  106.   * We do not implement everything in the DIRM.
  107.   * The DIRM does not specify all that AppleTM INTENDS DYLAN TO BE.
  108.   * There's no way to validate what a Dylan implementation is, even if we
  109.     had a full specification.
  110.  
  111. However, Mindy does implement most of what we believe Dylan will be.
  112.  
  113. Mindy was developed by the Gwydion Project at Carnegie Mellon University for
  114. our own internal use as a development tool while we work on our real
  115. high-performance Dylan implementation.  We have decided to make Mindy
  116. available for other people who want to learn about Dylan.  However, the
  117. amount of effort that we can put into maintaining Mindy is strictly limited.
  118.  
  119. Mindy will never be an industrial-strength implementation, and nobody should
  120. depend on it for real work.  We will make future releases from time to time
  121. as we add new features and fix bugs, but this is strictly a sideshow for us.
  122. We would appreciate receiving bug reports (especially those accompanied by
  123. code patches) and suggestions for improvements, but we may not fix every bug
  124. reported in a timely manner, or fix it at all.  Our work on development of
  125. the real Gwydion/Dylan must take precedence.
  126.  
  127. We hope that nobody will draw any conclusions about the performance of our
  128. future Gwydion/Dylan compiler or the performance attainable in Dylan from
  129. experience using Mindy.  It was not designed to be fast.
  130.  
  131. Mindy comprises two C programs, a compiler that produces byte-codes and a
  132. byte-code interpreter. Instructions for compiling and installing Mindy can
  133. be found in the file INSTALL at the top level of the Mindy release.  We have
  134. built and tested Mindy under MACH on the DECstation and HP-UX on HP 700's.
  135. We have built and run Mindy, but not tested it extensively, under OSF1 on
  136. the Alpha and Irix on the SGI.
  137.  
  138. 2.  Hello, World
  139. ----------------
  140. Well, the first program anyone should endeavor to write in a new language
  141. is, of course, Hello World.  Type this into a file called hw.dylan:
  142.  
  143.     module: dylan-user
  144.  
  145.     define method main (invocaton-name, #rest ignore)
  146.       puts("Hello, World.\n");
  147.     end;
  148.  
  149. To compile your program invoke $INSTALL/bin/mindycomp, for example:
  150.  
  151.     % $INSTALL/bin/mindycomp hw.dylan
  152.  
  153. This produces a file named hw.dbc.  The .dbc stands for "Dylan Byte
  154. Code". To run the program, say:
  155.  
  156.     % $INSTALL/bin/mindy -f hw.dbc
  157.  
  158. It should print "Hello, World." to standard output and then exit.
  159.  
  160. 3.   The Main Routine
  161. ---------------------
  162. After loading your program, Mindy invokes the generic function main from the
  163. Extensions module of the Dylan library.  Your program must define a method
  164. for main, or Mindy will signal a no applicable methods error and put you in
  165. the debugger.  For more information on the main function, see Section The
  166. Extensions Module.
  167.  
  168. It can be useful to load code into Mindy with no main method.  Once you land
  169. in the debugger, you can call any function manually.  This provides a way to
  170. test any library.
  171.  
  172. 4.   Multiple Files
  173. -------------------
  174. When working with a larger program, you will probably have more than one
  175. .dylan file.  In which case, you just compile them each independently, and
  176. then run Mindy with multiple -f switches:
  177.  
  178.     % mindy -f foo.dbc -f bar.dbc -f baz.dbc
  179.  
  180. Mindy loads the files specified with the -f switches in the order you
  181. specify the files on the command line.  This becomes important when you
  182. define your own modules (see Section Libraries and Modules).
  183.  
  184. If you typically load several .dbc files as part of a single program, you
  185. can combine them into one file for convenience.  The mechanism for combining
  186. .dbc files is the UnixTM CAT UTILITY:
  187.  
  188.     % cat foo.dbc bar.dbc baz.dbc > big.dbc
  189.     % mindy -f big.dbc
  190.  
  191. 5.  Syntax Errors
  192. -----------------
  193. If there are any syntax errors in your program, mindycomp will report them
  194. to stderr while compiling.  For example, if you had left off the closing
  195. parenthesis in the call to puts in the above example, mindycomp would have
  196. reported:
  197.  
  198.     hw.dylan:4: parse error at or before `;'
  199.  
  200. Because the line introduction, hw.dylan:4:,has the same format that the C
  201. compiler uses, gnu-emacs's compile package can parse the error messages from
  202. mindycomp.
  203.  
  204. Mindycomp's error recovery is not the best in the world.  Often, it has to
  205. completely punt, telling you only about the first few errors it found.  You
  206. have to fix what it reports and try again.
  207.  
  208. A hint to getting slightly tighter error recovery is to end all method and
  209. class definitions with "end method;" or "end class;".
  210. For example, if you forget an end token for a statement inside a method
  211. definition, the mindycomp parser goes all the way to the end of the file and
  212. then reports a syntax error at the EOF position.  You do not get any more
  213. clues.  If you use "end method;", then the parser can recover at
  214. the end of the method containing the bad syntax and reports the syntax error
  215. there.  This gives you a lot tighter recovery and more information in this
  216. situation.
  217.  
  218. 6.  Runtime Errors
  219. ------------------
  220. Much more common than syntax errors are runtime errors.  And given the
  221. simplistic model of compilation mindycomp uses, most semantic errors are not
  222. detected until runtime.  When Mindy hits a runtime error that is not handled
  223. via the condition system, it drops you into a debugger.  From this debugger
  224. you can look at variables, examine the stack, and invoke functions.  For
  225. example, if you had assumed that puts would be named something more
  226. reasonable, like put-string, you would have gotten the following when you
  227. tried to run your Hello World program:
  228.  
  229.     % mindy -f hw.dbc
  230.  
  231.     Warning: the following variables are undefined:
  232.       in library Dylan-user:
  233.         in module Dylan-user:
  234.           put-string[hw.dylan, line 9]
  235.  
  236.     thread [0] D   main
  237.     fp 0x1003009c: invoke-debugger({<simple-error> 0x101a24c9})
  238.     mindy> 
  239.  
  240. Typing help at the mindy> prompt will list the various commands you can use.
  241. See the document debug.ps for more information.
  242.  
  243. 7.  Internal Lossage
  244. --------------------
  245. Sometimes mindycomp or Mindy will get an internal error.  When this happens,
  246. it will print a message to stderr and then abort.  This results in the
  247. process dying due to some kind of signal.  On the pmax, this signal is
  248. SIGILL, or Illegal Instruction.  When this happens, send
  249. gwydion-bugs@cs.cmu.edu a piece of mail containing the error message and
  250. information on what it was you did that triggered the problem.
  251.  
  252. 8.  Dylan vs. Mindy Language Issues
  253. -----------------------------------
  254. The Dylan language is still changing slightly.  Mindy implements most of the
  255. Dylan Interim Reference Manual, some features that have been accepted but
  256. not described in the DIRM, and some features we would like to see accepted
  257. before the official language specification is published.  Currently, the
  258. Mindy diverges from the DIRM as described below:
  259.  
  260. Additions:
  261.  
  262.   * Mindy supports multiple value binding in the =/then clauses of for
  263.     statements.  This official status of this feature is uncertain at this
  264.     time.  The format of such a clause is
  265.  
  266.           (var1, var2, ...) = expr1 THEN expr2
  267.  
  268.   * Mindy supports keyed-by clauses in for statements.  The format of such a
  269.     clause is
  270.  
  271.           var KEYED-BY key IN collection
  272.  
  273.     Var is bound to each element in collection, and key is bound to the
  274.     element's key value.
  275.  
  276.   * Keyword parameters may have type information, and you can specify
  277.     default values with either Harlequin's proposed syntax (which uses
  278.     "= ...") or with Apple's syntax (which uses
  279.     "(...)").  Mindy does not enforce any congruence rules for
  280.     keyword parameter types, so effectively, keyword type information in
  281.     generic function declarations serves as documentation only.
  282.   * Mindy supports subclass specializers via the limited function.  A
  283.     subclass specializer causes a method to be invoked whenever the generic
  284.     function was called on a value that is the specified class or any
  285.     subclass of the specified class.  The method is never invoked on a value
  286.     that is an instance (direct or indirect) of the specified class, only
  287.     when the value is a subclass of the specified class.  The following is
  288.     an example:
  289.  
  290.            define method make
  291.               (result-class :: limited(<class>, subclass-of(<my-class>)));
  292.             let x = next-method();
  293.             do-special-logging-or-something(x);
  294.             x;
  295.           end method;
  296.  
  297. Deficiencies:
  298.  
  299.   * Sealed/open, abstract/concrete, and primary keywords are parsed where
  300.     allowed, but Mindy ignores this information about your program.
  301.   * Mindy does not parse the seal generic form.
  302.   * Library use chains cannot be circular; that is, there can be no cycles
  303.     in the graph representing library use relationships.
  304.   * Define method does not automatically insert #next next-method in
  305.     parameter lists.  You have to explicitly add it yourself.
  306.   * Case and select bodies cannot be empty.
  307.   * Make(<class>, ...) is unsupported.
  308.  
  309. 9.  Built-in Libraries and Modules
  310. ----------------------------------
  311. Mindy has full support for modules and libraries.  Mindy provides two
  312. built-in libraries, Dylan and Dylan-user.  The Dylan library contains the
  313. Dylan language implementation and the following exported modules:
  314.  
  315.     Dylan
  316.         This module contains the Dylan language implementation and exports
  317.         all the built-in Dylan definitions.
  318.     Extensions
  319.         This module exports useful extensions to the Dylan language (see
  320.         Section The Extensions Module).  Ultimately, there will be several,
  321.         more logically separate libraries that extend Dylan or provide an
  322.         application framework for users.  For now, we put any commonly used
  323.         utilities in the Extensions module.
  324.     System
  325.         This module exports an interface to operating system calls and
  326.         special, low-level functionality (see Section The System Module).
  327.     Introspection
  328.         This module exports reflective operations for examining classes,
  329.         functions, and so on.
  330.     File-descriptors
  331.         This module exports an interface to most standard C system calls
  332.         that operate on file descriptors.
  333.     Cheap-io
  334.         This module exports some basic, unextendable input and output
  335.         functionality.
  336.     Threads
  337.         This module exports an interface to threads, locks, and objects that
  338.         behave similarly to cthreads.h condition variables.
  339.  
  340. The Dylan-user library is the default library in which mindycomp compiles
  341. user code.  Mindy provides this library for user convenience when whipping
  342. up play code or small applications for which the programmer does not want to
  343. bother to create a library.  You cannot redefine the Dylan-user library.
  344. This library contains one module, Dylan-user, and you cannot redefine this
  345. module.
  346.  
  347. The Dylan language requires every library to contain a Dylan-user module,
  348. and this module must use the Dylan module from the Dylan library regardless
  349. of any user specifications.  This module provides a starting point in every
  350. library where users can begin to define modules; without an initial module
  351. in the library, you would be unable to write any code, including module
  352. definitions.  Each Dylan-user module in Mindy also automatically uses the
  353. modules from the Dylan library described above. You cannot redefine the
  354. Dylan-user module, so if your code requires module other than those
  355. described above, then you must define your own library and module.
  356.  
  357. Other libraries are available to Mindy users.  Later sections of this
  358. document describe these libraries.
  359.  
  360. 10.  Using Libraries and Modules
  361. --------------------------------
  362. To compile code into a particular library use the -l switch to mindycomp:
  363.  
  364.     % mindycomp -lmy-lib foo.dylan
  365.  
  366. If there is no -l switch, then mindycomp compiles the code into the
  367. Dylan-user library.  When loading a .dbc file into Mindy that was compiled
  368. into a particular library, one of the following conditions must be satisfied
  369. to avoid errors:
  370.  
  371.   * The library must be the Dylan-user library.  Technically, you could put
  372.     code in the Dylan library, but do not do this.
  373.   * You must have defined the library in a file previously loaded (see
  374.     Section Multiple Files for information on loading multiple files).
  375.   * The first piece of code in the source file that produced the .dbc file
  376.     must be the library definition.
  377.  
  378. While loading a file, if Mindy processes a library definition that uses an
  379. undefined library, then Mindy stops loading the current file, searches for
  380. the undefined library, and loads it.  After loading the undefined library,
  381. Mindy continues loading the current file and processing the original library
  382. definition.  Mindy searches for the undefined library in the directories
  383. listed in the MINDYPATH environment variable.  If MINDYPATH is undefined,
  384. then Mindy uses the pathname $INSTALL/lib.  In each directory, Mindy first
  385. looks for the file <library>-lib.dbc, where <library> is the name of the
  386. undefined library, and if this file does not exist, then Mindy looks for
  387. <library>.dbc.
  388.  
  389. Mindy loads the Dylan library when it first sees a reference to it.  A
  390. reference to the Dylan library occurs when loading a file compiled to be in
  391. the Dylan library, or when loading a file with a library definition that
  392. uses the Dylan library.  Mindy loads the Dylan library by looking for the
  393. file dylan.dbc on MINDYPATH.
  394.  
  395. To make a single compiled file for a library which has multiple source
  396. files, compile all the files that constitute the library with the -l switch
  397. set to the library's name.  Then cat all the resulting .dbc files together
  398. (see Section Multiple Files), making sure the file that defines the library
  399. is first.  Then install the combined .dbc file in one of the directories in
  400. your MINDYPATH.
  401.  
  402. To compile code into a particular module, use the module: file header.
  403. Whenever a source file lacks a module: file header, mindycomp issues a
  404. compiler warning and compiles the code into the Dylan-user module.  Note,
  405. this is the Dylan-user module of the library specified with the -l switch,
  406. and if there was no -l switch, it is the Dylan-user module of the Dylan-user
  407. library.
  408.  
  409. When loading a .dbc file into Mindy that was compiled into a particular
  410. module, one of the following conditions must be satisfied to avoid errors:
  411.  
  412.   * The module must be the Dylan-user module.
  413.   * You must have defined the module in a file previously loaded (see
  414.     Section Multiple Files for information on loading multiple files).
  415.   * The first code in the source file that produced the .dbc file must be
  416.     library and module definitions, and one of the module definitions must
  417.     be the module in question.
  418.  
  419. 11.  The Extensions Module
  420. --------------------------
  421. Ultimately, there will be several, more logically separate libraries that
  422. extend Dylan or provide an application framework for users.  For now, we put
  423. any commonly used utilities in the Extensions module.
  424.  
  425. 11.1.  Generally Useful Definitions
  426.  
  427. The Extensions module exports the following generally useful functionality:
  428.  
  429. <boolean>  [Class]
  430.  
  431.         This class is a subclass of <object>.  There are exactly two
  432.         instances of this class, #t and #f.
  433.  
  434. <byte-vector>  [Class]
  435.  
  436.         This class is a subclass of <vector> that can only hold integers
  437.         between 0 and 255 inclusively.  This class is a temporary addition
  438.         to Mindy to support the requirement that the Streams library export
  439.         a <byte-vector> definition.  When Mindy supports limited
  440.         collections, this may be defined within the Streams library.
  441.  
  442. <byte-character>  [Class]
  443.  
  444.         This class is a subclass of <character>. Characters of this type
  445.         represent the ASCII character set (or extensions to ASCII). Note, in
  446.         Mindy the <character> class is equivalent to unicode characters.
  447.  
  448. main  [Generic Function]
  449.  
  450.     Arguments
  451.         invocation-name :: <byte-string>
  452.         #rest arguments
  453.     Description
  454.         Has no methods, but is called by Mindy when it starts up.  To make a
  455.         standalone program, you define a method on main that does whatever
  456.         you want it to do.  Invocation-name is the first token on the
  457.         command line that invoked Mindy. Arguments is a sequence of strings.
  458.         There is a string in arguments for every argument on the command
  459.         line that invoked Mindy, except all -f switches and the argument
  460.         following each -f switch (that is, the file to load) is missing.
  461.         Remember that any module that adds a method to main must use the
  462.         Extensions module from the Dylan library.
  463.  
  464. one-of  [Constant]
  465.  
  466.         This function is useful in type expressions.  Because the union
  467.         function can only take two arguments, any type that is an
  468.         enumeration of three or more singleton values requires cascading
  469.         calls to union.  Combine that with having to wrap each value in a
  470.         call to singleton, and using union starts to create a lot of
  471.         parameter list bloat.  For example, the expression
  472.  
  473.             one-of(#"foo", #"bar", #"baz")
  474.  
  475.         is equivalent to
  476.  
  477.              union(singleton(#"foo"), union(singleton(#"bar"), singleton("baz")))
  478.  
  479. type-or  [Constant]
  480.  
  481.         This function is useful in type expressions.  Because the union
  482.         function can only take two arguments, any type that is the union of
  483.         three or more types requires cascading calls to union.  Using
  484.         type-or can be more convenient and more clear to read.  For example,
  485.         the expression
  486.  
  487.             type-or(<foo>, <bar>, <baz>, <quux>)
  488.  
  489.         is equivalent to
  490.  
  491.             union(<foo>, union(<bar>, union(<baz>, <quux>)))
  492.  
  493. false-or  [Constant]
  494.  
  495.         This function is useful in type expressions. It captures the common
  496.         idiom of returning an instance of a particular type or the value #f.
  497.         The expression
  498.  
  499.             false-or(<integer>)
  500.  
  501.         is equivalent to the expression
  502.  
  503.             union(<integer>, singleton(#f))
  504.  
  505. 11.2.  Debugger Customizations
  506.  
  507. The debugger uses the function report-condition to print conditions as error
  508. messages to users; for example, this is the function that implements the %S
  509. format-string directive for conditions. The debugger also uses the format
  510. function exported from the Cheap-io module to process format strings, and it
  511. prints directly to the Unix stdout passed to the Mindy process. If any
  512. library that you load into Mindy uses the Debugger-format library, then the
  513. debugger uses format from the Format library. You can extend how Mindy
  514. prints conditions, change what formatting function it uses, and direct where
  515. debugger output goes with the following:
  516.  
  517. report-condition  [Generic Function]
  518.  
  519.     Arguments
  520.         condition :: <condition>
  521.         stream :: <stream>
  522.     Values
  523.         meaningless :: singleton(#f)
  524.     Description
  525.         This is the function Mindy uses to print condition variables as
  526.         error messages to users. The internal format function used by Mindy
  527.         uses report-condition for condition arguments to the %S format
  528.         directive. The Format library's print-message method for conditions
  529.         calls report-condition.
  530.  
  531.         If you are writing a module that does no output but still provides
  532.         report-condition methods, you should consider using the value of
  533.         *format-function* to format output. Using *format-function* makes
  534.         your module more flexible for users of your module. If you call
  535.         Mindy's internal format, you'll be forced to write to only one
  536.         destination, Mindy's stdout, ignoring the stream argument. If you
  537.         call the Format library's format function, then your module will
  538.         require the Format, Print, and Streams libraries; therefore, users
  539.         of your module may ultimately load these other libraries needlessly.
  540.         Of course, if you want to make use of the extended functionality of
  541.         the Format library's format control strings, then you only have one
  542.         choice anyway, and there's no reason to use *format-function*.
  543.  
  544. *format-function*  [Variable]
  545.  
  546.         This variable holds a function that takes a stream, format string,
  547.         and format arguments. This function should force output when it is
  548.         done. The default value of this variable is a function that ignores
  549.         the stream argument and uses the format function from the Cheap-io
  550.         module.
  551.  
  552.         The Debugger-format library replaces the value of *format-function*
  553.         with a function that calls format from the Format library on the
  554.         stream argument, and then calls the Stream library's force-output
  555.         function on the stream argument.
  556.  
  557. *debug-output*  [Variable]
  558.  
  559.         The debugger uses the value of this variable when performing output.
  560.         The value must be a <stream> from the Streams library, or #f (the
  561.         default). When this variable is #f, the debugger outputs to stderr.
  562.  
  563. 11.3.  Tables
  564.  
  565. The Extensions module exports the following <table> subclasses:
  566.  
  567. <equal-table>  [Class]
  568.  
  569.         This class is a subclass of <table> that uses the \= function to
  570.         compare keys and the equal-hash function to generate hash codes.  If
  571.         you define your own classes and \= methods specialized on those
  572.         classes, then you should define a method for the equal-hash function
  573.         specialized to your classes (see the equal-hash function
  574.         description).
  575.  
  576. <value-table>  [Abstract Class]
  577.  
  578.         This class is a subclass of <table>.  Users can define subclasses of
  579.         this class and provide a method for tableprotocol that is
  580.         specialized to their new subclass.  Any subclass of <value-table>
  581.         must use a hash function that never use an object's identity (that
  582.         is, its location in the heap) as a means of computing a hash ID.
  583.         These tables are specifically designed to save overhead in testing
  584.         hash states and whether the table needs to be rehashed after garbage
  585.         collections.  The second value of the hash function should always be
  586.         $permanenthashstate.  For example:
  587.  
  588.            define class <my-table> (<value-table>)
  589.            end class;
  590.  
  591.            define method table-protocol (table :: <my-table>)
  592.              values(\=, string-hash);
  593.            end method;
  594.  
  595. The Extensions module exports the following functions to make it easier for
  596. users to use <equal-table>s and <valuetable>s:
  597.  
  598. equal-hash   [Generic Function]
  599.  
  600.     Arguments
  601.         key :: <object>
  602.     Values
  603.         hash-id :: <integer>
  604.         hash-state :: <object>
  605.     Description
  606.         This function returns a hash ID and hash state for use with
  607.         <equal-table>s.  If you define your own classes and \= methods
  608.         specialized on those classes, then you should define a method for
  609.         the equal-hash function specialized to your classes.  Specialized
  610.         methods exist for <number>, <character>, <function>, <symbol>, and
  611.         <collection>. The method for <object> returns the integer 42 and
  612.         $permanent-hash-state.  This function may use an object's identity
  613.         (that is, its location in the heap) to produce a hash ID.
  614.  
  615. collection-hash  [Function]
  616.  
  617.     Arguments
  618.         collection :: <collection>
  619.         key-hash-function :: <function>
  620.         elt-hash-function :: <function>)
  621.     Values
  622.         hash-id :: <integer>
  623.         hash-state :: <object>
  624.     Description
  625.         This function hashes every element of collection using
  626.         key-hash-function on the keys and element-hash-function on the
  627.         elements. Note, though two sequences may be equal according to the
  628.         \= function, sequence-hash and collection-hash may return different
  629.         hash codes for the sequences.
  630.  
  631. sequence-hash  [Function]
  632.  
  633.     Arguments
  634.         sequence :: <sequence>
  635.         elt-hash-function :: <function>
  636.     Values
  637.         hash-id :: <integer>
  638.         hash-state :: <object>
  639.     Description
  640.         This function hashes every element of sequence using
  641.         elt-hash-function, merging the resulting hash codes in order.  Note,
  642.         though two sequences may be equal according to the \= function,
  643.         sequence-hash and collection-hash may return different hash codes
  644.         for the sequences.
  645.  
  646. string-hash   [Function]
  647.  
  648.     Arguments
  649.         string :: <string>
  650.     Values
  651.         hash-id :: <integer>
  652.         hash-state :: <object>
  653.     Description
  654.         This function calls produces hash codes for strings without using
  655.         the strings' identities.  This function is suitable for use with
  656.         <value-table>s.
  657.  
  658. value-hash   [Generic Function]
  659.  
  660.     Arguments
  661.         object :: <object>
  662.     Values
  663.         hash-id :: <integer>
  664.         hash-state :: <object>
  665.     Description
  666.         This function produces hash codes for objects without using the
  667.         objects' identities.  This function is suitable for use with
  668.         <value-table>s. Mindy provides methods specialized for the following
  669.         types: <string>, <integer>, <float>, <character>, <symbol>,
  670.         singleton(#t), and singleton(#f).
  671.  
  672. 11.4.  Exiting Applications
  673.  
  674. The Extensions module exports the following functionality for controlling
  675. the exiting of applications:
  676.  
  677. exit  [Function]
  678.  
  679.     Arguments
  680.         #key exit-code :: <integer> = 0
  681.     Description
  682.         Causes the process to exit.  Mindy calls this function when there is
  683.         no code left to execute.
  684.  
  685. on-exit  [Function]
  686.  
  687.     Arguments
  688.         function :: <function>
  689.     Values
  690.         meaningless :: singleton(#f)
  691.     Description
  692.         Arranges for the exit function to call the argument function.  The
  693.         argument function must take no required arguments.  Users may call
  694.         on-exit multiple times to install more than one function for exit to
  695.         call, but the order in which exit invokes the functions is
  696.         undefined. Calling on-exit on the same function repeatedly, installs
  697.         that function multiple times.
  698.  
  699. 11.5.  Weak Pointers
  700.  
  701. The Extensions module exports the following weak-pointer functionality:
  702.  
  703. <weak-pointer>  [Class]
  704.  
  705.         This class is a subclass of <object>.  The make method for this
  706.         class takes the keyword parameter object:.  Instances of
  707.         <weak-pointer> refer to the object passed to the make method as long
  708.         as some other reference to the object exists.  Whenever an instance
  709.         of <weak-pointer> is the only reference to an object, and a garbage
  710.         collection occurs, then Mindy considers the object to be garbage.
  711.         When Mindy garbage collects an object referred to by a weak pointer,
  712.         then Mindy marks the weak pointer as being broken (see the
  713.         weak-pointer-object function).
  714.  
  715. weak-pointer-object   [Function]
  716.  
  717.     Arguments
  718.         wp :: <weak-pointer>
  719.     Values
  720.         object :: <object>
  721.         broken? :: <boolean>
  722.     Description
  723.         Returns the object referred to by the weak pointer and whether the
  724.         weak pointer is broken.  A weak pointer is broken when it contains
  725.         the only reference to an object, and in this situation,
  726.         weak-pointer-object returns the values #f and #t.
  727.  
  728. 11.6.  Collections
  729.  
  730. The Extensions module exports the following <collection> functionality:
  731.  
  732. key-exists?  [Generic Function]
  733.  
  734.     Arguments
  735.         collection :: <collection>
  736.         key :: <object>
  737.     Values
  738.         win? :: <boolean>
  739.         ele :: <object>
  740.     Description
  741.         Return whether key is in collection. If the key is in the
  742.         collection, then the second value is the element associated with
  743.         key; otherwise, the second return value is #f.
  744.  
  745. 12.   The System Module
  746. -----------------------
  747. The System module exports the following:
  748.  
  749. <buffer>  [Class]
  750.  
  751.         This class is a subclass of <vector>.  It is the built-in class in
  752.         Mindy that the Streams module supports.
  753.  
  754. copy-bytes  [Function]
  755.  
  756.     Arguments
  757.         dst :: type_or(<buffer>, <byte-vector>, <byte-string>)
  758.         dst-offset :: <integer>
  759.         src :: type_or(<buffer>, <byte-vector>, <byte-string>)
  760.         src-offset :: <integer>
  761.         count :: <integer>)
  762.     Values
  763.         dst :: type_or(<buffer, <byte-vector>, <byte-string>)
  764.     Description
  765.         Copies count bytes from src to dst, starting at src-offset and
  766.         dst-offset, respectively. This function returns dst.  This function
  767.         does no bounds checking.  Dst and src may be the same (\==) object;
  768.         this function ensures that it copies bytes from to the destination
  769.         portion correctly, regardless of overlap.
  770.  
  771. 13.  The Introspection Module
  772. -----------------------------
  773. The Introspection module exports reflective operations for examining
  774. classes, functions, and types.
  775.  
  776. 13.1.  Functions
  777.  
  778. Dylan provides some reflective operations for functions,
  779. function-specializers and instance?. With the latter, you can determine if a
  780. function is a <generic-function> or <method>, but neither Dylan nor Mindy
  781. provides exports class identifiers for other types of functions (such as
  782. block exit functions). The Subsection Types describes definitions that are
  783. also useful when inspecting methods because you can get detailed information
  784. about method specializer types.
  785.  
  786. The Introspection module exports the following for functions:
  787.  
  788. function-name  [Function]
  789.  
  790.     Arguments
  791.         function :: <function>
  792.     Values
  793.         result :: false-or(<symbol>)
  794.     Description
  795.         Returns the name of function as a <symbol> if function has a name;
  796.         otherwise function-name returns #f. All functions defined with
  797.         define generic or define method have names, and some other functions
  798.         have names.
  799.  
  800. 13.2.  Classes and Instances
  801.  
  802. The Introspection module exports the following for class objects, slot
  803. descriptions, and fetching and modifying the slot values of general objects:
  804.  
  805. class-name  [Function]
  806.  
  807.     Arguments
  808.         class :: <class>
  809.     Values
  810.         result :: false-or(<symbol>)
  811.     Description
  812.         Returns the name of class as a <symbol> if class has a name;
  813.         otherwise, this function returns #f. Mindy can always determine the
  814.         name of classes defined with define class.
  815.  
  816. <slot-descriptor>  [Class]
  817.  
  818.         This class is a subclass of <object>. The slot-descriptors function
  819.         returns instances of this class to describe the slots of a class
  820.         object.
  821.  
  822. slot-descriptors  [Function]
  823.  
  824.     Arguments
  825.         class :: <class>
  826.     Values
  827.         descriptors :: <list>
  828.     Description
  829.         Returns a list of <slot-descriptor>s for class. The result may be
  830.         the empty list.
  831.  
  832. slot-name  [Function]
  833.  
  834.     Arguments
  835.         slot :: <slot-descriptor>
  836.     Values
  837.         name :: <symbol>
  838.     Description
  839.         Returns the name of slot as a <symbol>.
  840.  
  841. slot-allocation  [Function]
  842.  
  843.     Arguments
  844.         slot :: <slot-descriptor>
  845.     Values
  846.         allocation :: one-of(#"instance", #"class", #"subclass",
  847.         #"constant", #"virtual")
  848.     Description
  849.         Returns the allocation type for slot as a <symbol>.
  850.  
  851. slot-type  [Function]
  852.  
  853.     Arguments
  854.         slot :: <slot-descriptor>
  855.     Values
  856.         type :: <type>
  857.     Description
  858.         Returns the type of values permitted for slot.
  859.  
  860. slot-getter  [Function]
  861.  
  862.     Arguments
  863.         slot :: <slot-descriptor>
  864.     Values
  865.         gf :: <generic-function>
  866.     Description
  867.         Returns the generic function that accesses slot.
  868.  
  869. slot-setter  [Function]
  870.  
  871.     Arguments
  872.         slot :: <slot-descriptor>
  873.     Values
  874.         gf :: <generic-function>
  875.     Description
  876.         Returns the generic function that stores into slot.
  877.  
  878. slot-value  [Function]
  879.  
  880.     Arguments
  881.         slot :: <slot-descriptor>
  882.         object :: <object>
  883.     Values
  884.         value :: <object>
  885.         initialized? :: <boolean>
  886.     Description
  887.         Returns the value for slot in object and #t. If the slot in the
  888.         object is uninitialized, then this function returns #f and #f. Note,
  889.         this function does not go through generic function dispatch, and it
  890.         calls no user methods; this function uses an internal primitive to
  891.         fetch the slot's value.
  892.  
  893. slot-value-setter  [Function]
  894.  
  895.     Arguments
  896.         value :: <object>
  897.         slot :: <slot-descriptor>
  898.         object :: <object>
  899.     Values
  900.         value :: <object>
  901.     Description
  902.         Stores value into slot of object and returns value. This function
  903.         performs whatever type checking is necessary to ensure value is safe
  904.         for slot.
  905.  
  906. 13.3.  Types
  907.  
  908. The Introspection module exports the following for inspecting types (and
  909. therefore, method specializers):
  910.  
  911. singleton-object  [Function]
  912.  
  913.     Arguments
  914.         specializer :: <singleton>
  915.     Values
  916.         object :: <object>
  917.     Description
  918.         This function returns the object of the singleton value type.
  919.  
  920. <subclass>  [Class]
  921.  
  922.         This class is a subclass of <type>. Instances of this class
  923.         represent subclass specializers. A subclass specializer causes a
  924.         method to be invoked whenever the generic function was called on a
  925.         value that is the specified class or any subclass of the specified
  926.         class (see Section Mindy vs. Dylan Language Issues for more
  927.         information). The function subclass-of returns the class specified
  928.         for the subclass specializer.
  929.  
  930. subclass-of  [Function]
  931.  
  932.     Arguments
  933.         specializer :: <subclass>
  934.     Values
  935.         class :: <class>
  936.     Description
  937.         Returns the class specified for the subclass specializer.
  938.  
  939. <limited-integer>  [Class]
  940.  
  941.         This class is a subclass of <type>. Instances of this class
  942.         represent limited integer types. See the functions
  943.         limited-integer-class, limited-integer-min, and limited-integer-max.
  944.  
  945. limited-integer-class  [Function]
  946.  
  947.     Arguments
  948.         specializer :: <limited-integer>
  949.     Values
  950.         class :: one-of(<fixed-integer>, <extended-integer>)
  951.     Description
  952.         Returns the class specified for the limited-integer specializer,
  953.         either <fixed-integer> or <extended-integer>.
  954.  
  955. limited-integer-min  [Function]
  956.  
  957. limited-integer-max  [Function]
  958.  
  959.     Arguments
  960.         specializer :: <limited-integer>
  961.     Values
  962.         class :: false-or(<integer>)
  963.     Description
  964.         Return the inclusive bounds of the limited-integer specializer. If
  965.         the minimum or maximum is unbounded, then the appropriate function
  966.         returns #f.
  967.  
  968. <union>  [Class]
  969.  
  970.         This class is a subclass of <type>. Instances of this class
  971.         represent union types. The function union-members returns a list of
  972.         the member types in the union.
  973.  
  974. union-members  [Function]
  975.  
  976.     Arguments
  977.         specializer :: <union>
  978.     Values
  979.         types :: <list>
  980.     Description
  981.         Returns the member types of the union type. The result may contain
  982.         more than two elements. This function collapses nested union types
  983.         to a flat list.
  984.  
  985. 13.4.  Miscellaneous
  986.  
  987. The Introspection module exports the following miscellaneous functionality:
  988.  
  989. object-address  [Function]
  990.  
  991.     Arguments
  992.         object :: <object>
  993.     Values
  994.         address :: <integer>
  995.     Description
  996.         Returns an integer for object. If the object is represented
  997.         internally represented as immediate data, then the integer returned
  998.         is only unique to the value of the object. If the object is
  999.         represented on the dynamic heap, then the integer uniquely
  1000.         identifies the object from all other objects.
  1001.  
  1002. 14.  The File-descriptor Module
  1003. -------------------------------
  1004. A cleaner interface to most of these functions is available from the Streams
  1005. library (see the document $INSTALL/doc/streams.{ps,txt}).  You probably do
  1006. not need to use the File-descriptor module, unless you are using fd-exec or
  1007. need an obscure file mode.
  1008.  
  1009. The File-descriptor module exports the following functions and constants:
  1010.  
  1011. fd-exec  [Function]
  1012.  
  1013.     Arguments
  1014.         command-line :: <string>
  1015.     Values
  1016.         in-fd :: false-or(<integer>)
  1017.         out-fd :: false-or(<integer>)
  1018.     Description
  1019.         This function provides a facility for running programs and scripts
  1020.         from within Mindy.  The command-line argument should contain the
  1021.         name of the program and all of the command line arguments for that
  1022.         program.  This function returns the file descriptors for the new
  1023.         process's standard input and output.  If fd-exec is unable to start
  1024.         the process, then it returns #f and #f.
  1025.  
  1026. fd-open  [Function]
  1027.  
  1028.     Arguments
  1029.         path :: <byte-string>
  1030.         flags :: <integer>
  1031.     Values
  1032.         fd :: false-or(<integer>)
  1033.         errno :: false-or(<integer>)
  1034.     Description
  1035.         This function calls the C open system call and returns the file
  1036.         descriptor and #f, if successful.  If the first value is #f, then
  1037.         the second value is the error number.  You can convert the error
  1038.         number to a string using the fderrorstring function.
  1039.  
  1040. fd-close  [Function]
  1041.  
  1042.     Arguments
  1043.         fd :: <integer>
  1044.     Values
  1045.         win? :: <boolean>
  1046.         errno :: false-or(<integer>)
  1047.     Description
  1048.         This function calls the C close system call and returns #t and #f,
  1049.         if successful.  If the first value is #f, then the second value is
  1050.         the error number.  You can convert the error number to a string
  1051.         using the fd-error-string function.
  1052.  
  1053. fd-read  [Function]
  1054.  
  1055.     Arguments
  1056.         fd :: <integer>
  1057.         buffer :: <buffer>
  1058.         offset :: <integer>
  1059.         count :: <integer>
  1060.     Values
  1061.         count :: false-or( <integer>)
  1062.         errno :: false-or(<integer>)
  1063.     Description
  1064.         This function calls the C read system call and returns the number of
  1065.         bytes read and #f, if successful.  Offset is an index into buffer,
  1066.         and it the index at which fd-read should start writing into the
  1067.         buffer.  All other arguments are the same as those described by the
  1068.         Unix man page.
  1069.  
  1070.         If the first value is #f, then the second value is the error number.
  1071.         You can convert the error number to a string using the
  1072.         fd-error-string function.
  1073.  
  1074.         This function does no bounds checking.
  1075.  
  1076. fd-write  [Function]
  1077.  
  1078.     Arguments
  1079.         fd :: <integer>
  1080.         buffer :: <buffer>
  1081.         offset :: <integer>
  1082.         count :: <integer>
  1083.     Values
  1084.         count :: false-or( <integer>)
  1085.         errno :: false-or(<integer>)
  1086.     Description
  1087.         This function calls the C write system call and returns the number
  1088.         of bytes written and #f, if successful.  Offset is an index into
  1089.         buffer, and it is the index at which fd-write should start reading
  1090.         from the buffer.  All other arguments are the same as those
  1091.         described by the Unix man page.
  1092.  
  1093.         If the first value is #f, then the second value is the error number.
  1094.         You can convert the error number to a string using the
  1095.         fd-error-string function.
  1096.  
  1097.         This function does no bounds checking.
  1098.  
  1099. fd-input-available?  [Function]
  1100.  
  1101.     Arguments
  1102.         fd :: <integer>
  1103.     Values
  1104.         input? :: <boolean>
  1105.         errno :: false-or(<integer>)
  1106.     Description
  1107.         This function returns whether there is any input available on the
  1108.         file descriptor.  The second return value is #f if
  1109.         fd-input-available? could determine whether input was available. If
  1110.         there is an error, the second return value is the error number.  You
  1111.         can convert the error number to a string using the fd-error-string
  1112.         function.
  1113.  
  1114. fd-sync-output  [Function]
  1115.  
  1116.     Arguments
  1117.         fd :: <integer>
  1118.     Values
  1119.         win? :: <boolean>
  1120.         errno :: false-or(<integer>)
  1121.     Description
  1122.         This function calls the C fsync system call and returns #t and #f,
  1123.         if successful.  If the first value is #f, then the second value is
  1124.         the error number.  You can convert the error number to a string
  1125.         using the fd-error-string function.
  1126.  
  1127. fd-seek  [Function]
  1128.  
  1129.     Arguments
  1130.         fd :: <integer>
  1131.         offset :: <integer>
  1132.         whence :: <integer>
  1133.     Values
  1134.         new-pos :: false-or(<integer>)
  1135.         errno :: false-or(<integer>)
  1136.     Description
  1137.         This function calls the C lseek system call and returns the new
  1138.         absolute position in the file and #f, if successful.  If the first
  1139.         value is #f, then the second value is the error number.  You can
  1140.         convert the error number to a string using the fd-error-string
  1141.         function.
  1142.  
  1143. fd-error-string  [Function]
  1144.  
  1145.     Arguments
  1146.         errno :: <integer>
  1147.     Values
  1148.         msg :: false-or(<byte-string>)
  1149.     Description
  1150.         This function calls the C strerror system call and returns the
  1151.         string that describes the given error number.  If the error number
  1152.         is unknown, then fd-error-string return #f.
  1153.  
  1154. L_SET  [Constant]
  1155.  
  1156. L_INCR  [Constant]
  1157.  
  1158. L_XTND  [Constant]
  1159.  
  1160. FNDELAY  [Constant]
  1161.  
  1162. FAPPEND  [Constant]
  1163.  
  1164. FCREAT  [Constant]
  1165.  
  1166. FTRUNC  [Constant]
  1167.  
  1168. FEXCL  [Constant]
  1169.  
  1170. O_RDONLY  [Constant]
  1171.  
  1172. O_WRONLY  [Constant]
  1173.  
  1174. O_RDWR  [Constant]
  1175.  
  1176. O_NDELAY  [Constant]
  1177.  
  1178. O_APPEND  [Constant]
  1179.  
  1180. O_CREAT  [Constant]
  1181.  
  1182. O_TRUNC  [Constant]
  1183.  
  1184. O_EXCL  [Constant]
  1185.  
  1186. ENOENT  [Constant]
  1187.  
  1188. EIO  [Constant]
  1189.  
  1190. ENXIO  [Constant]
  1191.  
  1192. EACCES  [Constant]
  1193.  
  1194. EFAULT  [Constant]
  1195.  
  1196. EEXIST  [Constant]
  1197.  
  1198. ENOTDIR  [Constant]
  1199.  
  1200. EISDIR  [Constant]
  1201.  
  1202. EINVAL  [Constant]
  1203.  
  1204. ENFILE  [Constant]
  1205.  
  1206. EMFILE  [Constant]
  1207.  
  1208. ETXTBSY  [Constant]
  1209.  
  1210. ENOSPC  [Constant]
  1211.  
  1212. EROFS  [Constant]
  1213.  
  1214. EOPNOTSUPP  [Constant]
  1215.  
  1216. ELOOP  [Constant]
  1217.  
  1218. ENAMETOOLONG  [Constant]
  1219.  
  1220. EDQUOT  [Constant]
  1221.  
  1222. EBADF  [Constant]
  1223.  
  1224. EINTR  [Constant]
  1225.  
  1226. EWOULDBLOCK  [Constant]
  1227.  
  1228. EPIPE  [Constant]
  1229.  
  1230. EFBIG  [Constant]
  1231.  
  1232.         These constants are the same constants from the standard C
  1233.         libraries, file.h and errno.h.  The File-descriptors module exports
  1234.         all the constants users need to call the functions in the module, or
  1235.         test the functions' return values.
  1236.  
  1237. 15.  The Cheap-io Module
  1238. ------------------------
  1239. The Cheap-io module exports some basic, unextendable I/O functionality.
  1240. Mindy uses the Cheap-io functions internally. The Gwydion Project also
  1241. provides the Streams, Print, and Format libraries (see the $INSTALL/doc/
  1242. directory for documentation). If any library that you load into Mindy uses
  1243. the Debugger-format library, then the debugger uses format from the Format
  1244. library.
  1245.  
  1246. format  [Function]
  1247.  
  1248.     Arguments
  1249.         control-string :: <byte-string>
  1250.         #rest arguments
  1251.     Values
  1252.         meaningless :: singleton(#f)
  1253.     Description
  1254.         This format adheres to the format strings described in the Dylan
  1255.         Interim Reference Manual with one exception.  Mindy incorrectly
  1256.         prints instances of <condition> supplied to the %S directive. The
  1257.         Format library provides a correct format function that supports an
  1258.         upward-compatible extension to the format control strings described
  1259.         in the DIRM.
  1260.  
  1261. print  [Function]
  1262.  
  1263. prin1  [Function]
  1264.  
  1265.     Arguments
  1266.         object :: <object>
  1267.     Values
  1268.         meaningless :: singleton(#f)
  1269.     Description
  1270.         Prints thing to stdout.  Print follows thing with a newline.  You
  1271.         cannot extend or specialize how objects are printed because these
  1272.         function's are written in C code, within Mindy's implementation.
  1273.  
  1274. puts  [Function]
  1275.  
  1276.     Arguments
  1277.         string :: <byte-string>
  1278.     Values
  1279.         meaningless :: singleton(#f)
  1280.     Description
  1281.         Prints the contents of string. to stdout.
  1282.  
  1283. putc  [Function]
  1284.  
  1285.     Arguments
  1286.         char :: <byte-character>
  1287.     Values
  1288.         meaningless :: singleton(#f)
  1289.     Description
  1290.         Prints char to stdout.
  1291.  
  1292. getc  [Function]
  1293.  
  1294.     Arguments
  1295.         NONE
  1296.     Values
  1297.         char :: <byte-character>
  1298.     Description
  1299.         Read and return the next character from stdin.  Returns #f at EOF.
  1300.  
  1301. fflush  [Function]
  1302.  
  1303.     Arguments
  1304.         none
  1305.     Values
  1306.         meaningless :: singleton(#f)
  1307.     Description
  1308.         Forces out any pending output generated by format, print, prin1,
  1309.         puts, and putc.
  1310.  
  1311. 16.  The Threads Module
  1312. -----------------------
  1313. This module is in the Dylan library and exports an interface to <thread>s,
  1314. <lock>s, and <event>s (objects on which threads can wait until a signalling
  1315. thread indicates the events have occurred).
  1316.  
  1317. 16.1.  Classes and Functions
  1318.  
  1319. The Threads module exports the following classes and functions:
  1320.  
  1321. <thread>  [Class]
  1322.  
  1323.         This class is a subclass of <object>.  Instances of this class are
  1324.         the handles by which programs manipulate threads.
  1325.  
  1326. spawn-thread  [Function]
  1327.  
  1328.     Arguments
  1329.         debug-name :: <byte-string>
  1330.         init-function :: <function>
  1331.     Values
  1332.         thread :: <thread>
  1333.     Description
  1334.         Spawns a concurrent asynchronous thread and invokes init-function in
  1335.         that thread.  The dynamic context of the thread is the same as if it
  1336.         were the main thread of a program at the beginning of the program's
  1337.         execution.
  1338.  
  1339. kill-thread  [Function]
  1340.  
  1341.     Arguments
  1342.         thread :: <thread>
  1343.     Values
  1344.         thread :: <thread>
  1345.     Description
  1346.         Kills thread immediately.  After calling this function, the argument
  1347.         thread never executes again.
  1348.  
  1349. <lock>  [Abstract Class]
  1350.  
  1351.         This class is a subclass of <object>.  Instances of this class
  1352.         provide logical locks.  A lock is locked when a thread successfully
  1353.         grabs a lock, and we say the thread holds the lock.  Holding a lock
  1354.         in no way prohibits access to a resource.  It is purely the
  1355.         convention of various threads to access a shared resource only after
  1356.         successfully grabbing a lock.  If <lock> is passed to make, make
  1357.         returns a <spinlock>.
  1358.  
  1359. <spinlock>  [Sealed Class]
  1360.  
  1361.         This class is a subclass of <lock>.  Instances of this class provide
  1362.         a single-locking model. Whenever a <spinlock> is locked, any thread
  1363.         that tries to grab it will block. Whenever a <spinlock> is locked,
  1364.         any thread may release it. Whenever a <spinlock> is unlocked, any
  1365.         thread may grab it.
  1366.  
  1367.         <spinlock>s are designed to be held for a very short period of time,
  1368.         several machine instructions at most.  Threads should only hold a
  1369.         <spinlock> for a very short period of time because other threads
  1370.         that are waiting for the lock are blocked and could be wasting CPU
  1371.         cycles by busy looping; that is, waiting for a <spinlock> does not
  1372.         necessarily use anything as heavy weight as a system call to sleep
  1373.         the thread waiting for the lock.  If only a couple threads are
  1374.         sharing a resource, it may be more efficient to actually hold a
  1375.         <spinlock> for a moderate amount of time while performing a
  1376.         high-level operation, rather than use a lock to build a more
  1377.         heavy-weight mutual exclusion mechanism (such as a semaphore) to
  1378.         isolate access to the shared resource.
  1379.  
  1380.         Unlocking a <spinlock> when it is already unlocked signals an error.
  1381.  
  1382. <multilock>  [Sealed Class]
  1383.  
  1384.         This class is a subclass of <lock>.  Instances of this class provide
  1385.         a multilocking model. Whenever a <multilock> is unlocked, any thread
  1386.         may grab it.  A thread that holds a <multilock> may grab the lock
  1387.         repeatedly without releasing the lock.  Each grab effectively
  1388.         increments a counter, and each release effectively decrements a
  1389.         counter.  A <multilock> is available to be grabbed by any thread
  1390.         when the counter returns to zero; therefore, a thread must release
  1391.         the lock for each grabbing of the lock.  This behavior is useful for
  1392.         implementing a high-level operation that needs to isolate access to
  1393.         a resource while calling a few lower-level operations that lock the
  1394.         resource; in this way, the high-level operation effectively calls
  1395.         all the lower-level operations atomically with no other threads
  1396.         affecting the state of the resource between the calls.
  1397.  
  1398.         Whenever a <multilock> is locked, only the thread that holds the
  1399.         lock may release it.
  1400.  
  1401.         <multilock>s are designed to be held for as long as a thread
  1402.         requires. When other threads call the grab-lock function and block
  1403.         because a <multilock> is locked, the other threads are guaranteed to
  1404.         sleep until the lock is available.
  1405.         Unlocking a <multilock> when it is already unlocked signals an
  1406.         error.
  1407.  
  1408. <semaphore>  [Sealed Class]
  1409.  
  1410.         This class is a subclass of <lock>.  Instances of this class provide
  1411.         a single-locking model.
  1412.  
  1413.         Whenever a <semaphore> is unlocked, any thread may grab it.
  1414.         Whenever a <semaphore> is locked, any thread that tries to grab it
  1415.         will block. Whenever a d is locked, any thread may release it.
  1416.  
  1417.         <semaphore>s are designed to be held for as long as a thread
  1418.         requires. When other threads call the grab-lock function and block
  1419.         because a <semaphore> is locked, the other threads are guaranteed to
  1420.         sleep until the lock is available.
  1421.  
  1422.         Unlocking a <semaphore> when it is already unlocked signals an
  1423.         error.
  1424.  
  1425. locked?  [Function]
  1426.  
  1427.     Arguments
  1428.         lock :: <lock>
  1429.     Values
  1430.         locked? :: <boolean>
  1431.     Description
  1432.         Returns whether the lock is held by any thread.
  1433.  
  1434. grab-lock  [Generic Function]
  1435.  
  1436.     Arguments
  1437.         lock :: <lock>
  1438.     Values
  1439.         meaningless :: singleton(#f)
  1440.     Description
  1441.         Returns after successfully grabbing the lock.  If the lock is not
  1442.         immediately available, this function waits for the lock to become
  1443.         available.
  1444.  
  1445. grab-lock  [G.F. Method]
  1446.  
  1447.     Arguments
  1448.         lock :: <spinlock>
  1449.     Values
  1450.         meaningless :: singleton(#f)
  1451.     Description
  1452.         Returns after successfully grabbing the lock.  This method can only
  1453.         grab lock when it is unlocked.  When the lock is held, this method
  1454.         may busy-loop until the lock is unlocked.
  1455.  
  1456. grab-lock  [G.F. Method]
  1457.  
  1458.     Arguments
  1459.         lock :: <semaphore>
  1460.     Values
  1461.         meaningless :: singleton(#f)
  1462.     Description
  1463.         Returns after successfully grabbing the lock.  This method can only
  1464.         grab lock when it is unlocked.  When the lock is held, this method
  1465.         puts the calling thread to sleep until the lock is available.
  1466.  
  1467. grab-lock  [G.F. Method]
  1468.  
  1469.     Arguments
  1470.         lock :: <multilock>
  1471.     Values
  1472.         meaningless :: singleton(#f)
  1473.     Description
  1474.         Returns after successfully grabbing the lock.  A single thread may
  1475.         successfully call this method repeatedly, but the thread must call
  1476.         release-lock once for each call to grab-lock.  If the thread calls
  1477.         release-lock fewer times than grab-lock, the lock remains locked,
  1478.         and any threads waiting for the lock will continue to wait.  When a
  1479.         thread that does not hold the lock calls this method, the method
  1480.         puts the calling thread to sleep until the lock is available.
  1481.  
  1482. release-lock  [Generic Function]
  1483.  
  1484.     Arguments
  1485.         lock :: <lock>
  1486.     Values
  1487.         meaningless :: singleton(#f)
  1488.     Description
  1489.         Releases the lock.  If lock is unlocked, this function signals an
  1490.         error.
  1491.  
  1492. release-lock  [G.F. Method]
  1493.  
  1494.     Arguments
  1495.         lock :: union(<spinlock>, <semaphore>)
  1496.     Values
  1497.         meaningless :: singleton(#f)
  1498.     Description
  1499.         Releases the lock. If lock is unlocked, this function signals an
  1500.         error. Any thread may unlock a <spinlock> or <semaphore>, regardless
  1501.         of whether it is the thread that successfully grabbed the lock.
  1502.  
  1503. release-lock  [G.F. Method]
  1504.  
  1505.     Arguments
  1506.         lock :: <multilock>
  1507.     Values
  1508.         meaningless :: singleton(#f)
  1509.     Description
  1510.         Releases the lock. If lock is unlocked, this function signals an
  1511.         error. Only the thread that holds lock may call this function, and
  1512.         if another thread tries to release the lock, this method signals an
  1513.         error.  When this function returns, lock may still be locked.  A
  1514.         thread that has repeatedly grabbed a <multilock> must call
  1515.         release-lock once for each call to grab-lock.
  1516.  
  1517. <event>  [Class]
  1518.  
  1519.         This class is a subclass of <object>.  Threads use events to block
  1520.         without busy looping and to communicate to other threads that they
  1521.         should wake up.
  1522.  
  1523. wait-for-event  [Generic Function]
  1524.  
  1525.     Arguments
  1526.         event :: <event>
  1527.         lock :: <lock>
  1528.     Values
  1529.         meaningless :: singleton(#f)
  1530.     Description
  1531.         Releases the lock and puts the calling thread to sleep until some
  1532.         other thread signals event.  After this function returns, the lock
  1533.         is unheld, and the calling thread must try to grab the lock before
  1534.         accessing any shared resources.  Due to implementation details, this
  1535.         function may return even when the lock is unavailable, or the event
  1536.         has not truly occurred; because of this, programs need to loop over
  1537.         wait-for-event and grab-lock, testing that the event actually
  1538.         occurred.  Methods exist for both <spinlock>s and <semaphore>s.
  1539.  
  1540. signal-event  [Function]
  1541.  
  1542.     Arguments
  1543.         event :: <event>
  1544.     Values
  1545.         meaningless :: singleton(#f)
  1546.     Description
  1547.         Signals that the event occurred, indicating that Mindy should wake
  1548.         up a thread that is waiting on this event.
  1549.  
  1550. broadcast-event  [Function]
  1551.  
  1552.     Arguments
  1553.         <event>
  1554.     Values
  1555.         meaningless :: singleton(#f)
  1556.     Description
  1557.         Signals that the event occurred and causes Mindy to wake up every
  1558.         thread that is waiting on this event.
  1559.  
  1560. 16.2.  Examples
  1561.  
  1562. The following code shows how to use locks and events to isolate access to a
  1563. queue:
  1564.  
  1565.     // This example shows two routines, get-queue and release-queue.  Code 
  1566.     // that accesses the queue should call get-queue before doing so and call
  1567.     // release-queue when done.  Any code failing to isolate access to the
  1568.     // queue in this way has undefined behavior and is incorrectly written.
  1569.     //
  1570.     // This variable is #t if and only if the queue is generally available.
  1571.     //
  1572.     define variable queue-available? = #t;
  1573.     // This constant holds an event object used to signal when the queue 
  1574.     // becomes generally available again.
  1575.     //
  1576.     define constant queue-available = make(<event>);
  1577.     // This constant holds a lock object used to isolate access to
  1578.     // queue-available? for testing and setting purposes.
  1579.     //
  1580.     define constant queue-lock = make(<lock>);
  1581.     // When this function returns, the caller has exclusive access to the 
  1582.     // queue.  If necessary, this function waits for the queue to become 
  1583.     // available, but it does not busy loop.  This function returns #f as 
  1584.     // a meaningless return value. 
  1585.     //
  1586.     define method get-queue ()
  1587.       grab-lock(queue-lock); 
  1588.       while (~ queue-available?)
  1589.         wait-for-event(queue-available, queue-lock);
  1590.         grab-lock(queue-lock);
  1591.       end;
  1592.       queue-available? := #f;
  1593.       lock-release(queue-lock);
  1594.       #f;
  1595.     end;
  1596.     // This function releases the queue and signals that it is released so 
  1597.     // that someone waiting on the queue will be woken up.  This function 
  1598.     // returns #f as a meaningless return value. 
  1599.     //
  1600.     define method release-queue ()
  1601.       grab-lock(queue-lock);
  1602.       queue-available? := #t;
  1603.       release-lock(queue-lock);
  1604.       signal-event(queue-available);
  1605.       #f;
  1606.     end;
  1607.  
  1608. The following example shows how to use a lock to isolate queue access in a
  1609. different way than the previous example:
  1610.  
  1611.     // This constant holds an event object used to signal when an element 
  1612.     // exists in the queue. 
  1613.     //
  1614.     define constant something-available = make(<event>);
  1615.     // This constant holds a lock that is held whenever a thread is accessing 
  1616.     // queue.
  1617.     //
  1618.     define constant lock = make(<lock>);
  1619.     // This constant holds a queue object.
  1620.     //
  1621.     define constant queue = make(<deque>);
  1622.     // This function returns an element from queue.  If no element is 
  1623.     // immediately available, then this function blocks until it can return 
  1624.     // an element.  This function assumes only one or two other threads are 
  1625.     // ever waiting for the queue, and it assumes pop is a fast high-level 
  1626.     // operation. 
  1627.     //
  1628.     define method get-something()
  1629.       grab-lock(lock);
  1630.       while (empty?(queue))
  1631.         wait-for-event(something-available, lock);
  1632.         grab-lock(lock);
  1633.       end;
  1634.       let result = pop(queue);
  1635.       lock-release(lock);
  1636.       result;
  1637.     end;
  1638.     // This function adds thing to queue.  It assumes only one or two other 
  1639.     // threads are ever waiting for the queue, and it assumes push is a fast 
  1640.     // high-level operation. 
  1641.     //
  1642.     define method put-something(thing)
  1643.       grab-lock(lock);
  1644.       push(queue, thing);
  1645.       release-lock(lock);
  1646.       signal-event(something-available);
  1647.     end;
  1648.  
  1649. 17.   Streams Library
  1650. ---------------------
  1651. There is a Streams library that adheres to the Gwydion streams
  1652. specification.  For documentation on the stream specification, see the file
  1653. $INSTALL/doc/streams.{ps,txt}.
  1654.  
  1655. The Streams library exports two modules, Streams and Standard-io.  The
  1656. Streams module exports all identifiers from the streams specification.  The
  1657. Streams module also exports <fd-stream>:
  1658.  
  1659. <fd-stream>  [Class]
  1660.  
  1661.         This class is a subclass of <stream>.  These streams are based on C
  1662.         file descriptors, and they do not adhere to the Random Access
  1663.         Protocol described in the Gwydion streams specification.  The make
  1664.         method accepts the following keywords:
  1665.  
  1666.         direction:
  1667.             This keyword is optional and defaults to #"input".  When
  1668.             supplied, it must be either #"input" or #"output".
  1669.         FD:
  1670.             This keyword is required and should be an open file-descriptor.
  1671.         SIZE:
  1672.             This keyword is optional and is the size of the buffer.  See the
  1673.             Streams specification for details.
  1674.  
  1675. The Standard-io module exports the following:
  1676.  
  1677. *standard-input*  [Constant]
  1678.  
  1679. *standard-output*  [Constant]
  1680.  
  1681. *standard-error*  [Constant]
  1682.  
  1683.         These have the following values respectively:
  1684.  
  1685.             make(<fd-stream>, fd: 0)
  1686.             make(<fd-stream>, fd: 1, direction: #"output")
  1687.             make(<fd-stream>, fd: 2, direction: #"output")
  1688.  
  1689. 18.  Integers
  1690. -------------
  1691. Mindy's <integer> class is abstract. Mindy provides two concrete classes,
  1692. <fixed-integer> and <extended-integer>. Both concrete classes are direct
  1693. subclasses of <integer>. Expressions involving <extended-integer>s produce
  1694. <extendedinteger> results because <extended-integer>s are contagious. If an
  1695. expression involving only <fixed-integer> values would produce a result that
  1696. does not fit in a <fixed-integer>, then Mindy signals an overflow error. You
  1697. can use the as function to convert back and forth between <fixed-integer>s
  1698. and <extended-integer>s. As signals an error when converting an
  1699. <extended-integer> to a <fixed-integer>, and the value does not fit in a
  1700. <fixed-integer>.
  1701.  
  1702. Mindycomp parses all integer literals as <fixed-integer>s. If a literal does
  1703. not fit in a <fixed-integer>, then mindycomp issues a compiler error. Though
  1704. the compiler supports no literal syntax for <extended-integer>s, the Mindy
  1705. debugger prints them in a #eDDD... format where each D is a decimal digit.
  1706.  
  1707. The Extension module of the Dylan library exports the following constants:
  1708.  
  1709. $maximum-fixed-integer  [Constant]
  1710.  
  1711. $minimum-fixed-integer  [Constant]
  1712.  
  1713.         These constants hold the largest positive <fixed-integer> and the
  1714.         largest negative <fixed-integer>.
  1715.  
  1716. 19.  Miscellaneous Implementation Choices
  1717. -----------------------------------------
  1718. The error method specialized on <byte-string> applies the format function to
  1719. the arguments passed to error.  See Section The Extensions Module for the
  1720. details of format from the Cheap-io module of the Dylan library. See
  1721. $INSTALL/doc/format.{ps,txt} for the details of format from the Format
  1722. library.
  1723.  
  1724. Rest arguments in Mindy are <sequence>s.  You cannot use any functions on
  1725. the rest argument that assumes the collection is an instance of any class
  1726. more specific than <sequence>; for example, you cannot use the head or tail
  1727. functions because they operate on instances of <pair>.
  1728.  
  1729. Mindy's <character> implementation is equivalent to unicode characters. The
  1730. <byte-character> class exported from the Extensions module of the Dylan
  1731. library is a subclass of <character>.
  1732.  
  1733. 20.  Copyright and Terms of Use
  1734. -------------------------------
  1735. Copyright (c) 1994  Carnegie Mellon University All rights reserved.
  1736.  
  1737. Use and copying of this software and preparation of derivative works based
  1738. on this software are permitted, including commercial use, provided that the
  1739. following conditions are observed:
  1740.  
  1741.   * This copyright notice must be retained in full on any copies and on
  1742.     appropriate parts of any derivative works.
  1743.   * Documentation (paper or online) accompanying any system that
  1744.     incorporates this software, or any part of it, must acknowledge the
  1745.     contribution of the Gwydion Project at Carnegie Mellon University.
  1746.  
  1747. This software is made available as is.  Neither the authors nor Carnegie
  1748. Mellon University make any warranty about the software, its performance, or
  1749. its conformity to any specification.
  1750.  
  1751. Bug reports, questions, comments, and suggestions should be sent by E-mail
  1752. to the Internet address gwydionbugs@cs.cmu.edu.
  1753.  
  1754.